package mango.orm;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;

import mango.orm.DBSession;



@SuppressWarnings("rawtypes")
public abstract class DaoIterator<E> implements Iterator {
    protected DBSession session;
    protected boolean selfClose;
    protected ResultSet rs;
    protected Class retType;
    protected boolean hasNext;
//    protected int rowNum = 0;
    protected String dbType;
    protected Dao dao;

    public DaoIterator(Dao dao, DBSession session, boolean selfClose, ResultSet rs,
            Class retType) throws SQLException {
        this.dao = dao;
        this.session = session;
        this.selfClose = selfClose;
        this.rs = rs;
        this.retType = retType;
        this.dbType = this.session.getConnector().getDbType();
        this.postNext();
    }

    protected void postNext() throws SQLException {
        this.hasNext = this.rs.next();
        if (!this.hasNext) {
            dao.close();
        }
//        else {
//            rowNum++;
//        }
    }

    public boolean hasNext() {
        return this.hasNext;
    }

    public abstract E next();

    public void remove() {
    }
}
